<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>酒店后台管理系统</title>
  <link rel="stylesheet" href="css/layui.css">
  <script src="js/jquery.min.js"></script>
  <script>
	$(function(){
		
		var url = "ws://169.254.106.77:8080/WebSocketHandler/";
		var ws = null;
		//连接服务器
		var userName = $("#userName").val();
		url = url + userName; //传递用户名
		//创建对象，连接服务器
		ws=new WebSocket(url);
		//给ws对象绑定事件
		//连接事件
		ws.onopen = function(){
			console.info("连接服务器成功");
		}
		//接收到消息
		ws.onmessage = function(result){
			var data = $.parseJSON(result.data);
			var order = "";
			order =order +'<table class="layui-table" lay-skin="line">'
			+'<colgroup><col width="150"><col width="200"><col></colgroup>'
			+'<thead>'
			+'<tr><th style="width: 150px;">订单号：'+data.onumber+'</th><th></th><th></th><th></th><th></th>'
			+'<th><button type="button" class="layui-btn layui-btn-xs layui-btn-danger" id="pass_message" value="通过">通过</button><button type="button" class="layui-btn layui-btn-xs layui-btn-danger" id="nopass_message" value="清空">清空</button></th></tr>'
			+'</thead><tbody>';
			for(var j=0;j<data.orderDetails.length;j++){
				order=order+'<tr id="roomtype">'
				+'<td>'+data.orderDetails[j].rid+'</td>'
				+'<td style="color: rgb(238 44 44);font-size: 15px; font-weight: 600;">'+data.orderDetails[j].newprice+'</td>'
				+'<td>'+data.orderDetails[j].guest.gname+'</td>'
				+'<td>'+data.orderDetails[j].guest.gidcard+'</td>'
				+'<td>'+data.orderDetails[j].checkin+'</td>'
				+'<td>'+data.orderDetails[j].scheckout+'</td></tr>';
			}
			order=order+'</tbody></table>';
			$("#add_message").html(order);
		}
		//关闭连接
		ws.onclose = function(){
			alert("断开连接");
		}
		
		$("#pass_message").click(function(){
			var message=$("#pass_message").val();
			alert(message);
			if(ws!=null){
				ws.send(message); //发送消息
			}
		})
		
		$("#nopass_message").click(function(){
			var message=$("#nopass_message").val();
			alert(message);
			if(ws!=null){
				ws.send(message); //发送消息
			}
		})
			
		//断开连接
		$("#cancel").click(function(){
			if(ws!=null){
				ws.close();
			}
		});	

		$.ajax({
			url:"/order/find",
			type:"post",
			success:function(data){
				if(data!=null){
					var order = "";
					order =order +'<table class="layui-table" lay-skin="line">'
					+'<colgroup><col width="150"><col width="200"><col></colgroup>'
					+'<thead>'
					+'<tr><th style="width: 150px;">订单号：'+data.onumber+'</th><th></th><th></th><th></th><th></th>'
					+'<th><button type="button" class="layui-btn layui-btn-xs layui-btn-danger" id="pass_message" value="通过">通过</button><button type="button" class="layui-btn layui-btn-xs layui-btn-danger" id="nopass_message" value="清空">清空</button></th></tr>'
					+'</thead><tbody>';
					for(var j=0;j<data.orderDetails.length;j++){
						order=order+'<tr id="roomtype">'
						+'<td>'+data.orderDetails[j].rid+'</td>'
						+'<td style="color: rgb(238 44 44);font-size: 15px; font-weight: 600;">'+data.orderDetails[j].newprice+'</td>'
						+'<td>'+data.orderDetails[j].guest.gname+'</td>'
						+'<td>'+data.orderDetails[j].guest.gidcard+'</td>'
						+'<td>'+data.orderDetails[j].checkin+'</td>'
						+'<td>'+data.orderDetails[j].scheckout+'</td></tr>';
					}
					order=order+'</tbody></table>';
					$("#add_message").html(order);
				}
				}
		})
	})
  </script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    <div class="layui-logo">酒店后台管理系统</div>
    <!-- 头部区域（可配合layui已有的水平导航） -->
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item">
        <a href="javascript:;">
          <img src="http://t.cn/RCzsdCq" class="layui-nav-img">
          贤心
        </a>
        <dl class="layui-nav-child">
          <!-- <dd><a href="">消息<span class="layui-badge">99+</span></a></dd> -->
        </dl>
      </li>
      <li class="layui-nav-item"><a href="logout">退了</a></li>
    </ul>
  </div>
  
  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
     <ul class="layui-nav layui-nav-tree"  lay-filter="test">
        <li class="layui-nav-item layui-nav-itemed">
          <a class="" href="javascript:;">订单管理</a>
          <dl class="layui-nav-child">
            <dd><a href="/html/offline.html">线下开单</a></dd>
            <dd><a href="/checkin.html">线下开房</a></dd>
            <dd><a href="/html/checkout.html">宾客结账</a></dd>
            <dd><a href="/html/order.html">订单管理</a></dd>
          </dl>
        </li>
       <li class="layui-nav-item">
          <a href="javascript:;">营业查询</a>
          <dl class="layui-nav-child">
            <dd><a href="/selguest.html">入住宾客查询</a></dd>
            <dd><a href="/turnover.html">日/月营业查询</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item">
          <a href="javascript:;">系统设置</a>
          <dl class="layui-nav-child">
            <dd><a href="/vip.html">VIP设置</a></dd>
        		<dd><a href="/discount.html">计费设置</a></dd>
        		<dd><a href="/room.html">房间设置</a></dd>
				<dd><a href="/admin.html">操作员设置</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item"><a href="/html/confirm.html">推送消息</a></li>
      </ul>
    </div>
  </div>
  
  <div class="layui-body">
    <!-- 内容主体区域 -->
    <input type="hidden" id="userName" value="后台">
		<div class="layui-order-message">
			订单信息
		<hr class="layui-bg-green">
		</div>
		<div id="order_message">
		
		</div>
		<div class="table_class" style="width:1000px; margin-left: 50px;" id="add_message">
			<table class="layui-table" lay-skin="line">
				<colgroup>
					<col width="150">
					<col width="200">
					<col>
				</colgroup>
				<thead>
					<tr>
						<th style="width: 150px;">订单号</th>
						<th></th>
						<th></th>
						<th></th>
						<th></th>
						<th></th>
						<th><button type="button" class="layui-btn layui-btn-xs layui-btn-danger" id="pass_message" value="通过">通过</button><button type="button" class="layui-btn layui-btn-xs layui-btn-danger" id="nopass_message" value="清空">清空</button></th>
					</tr> 
				</thead>
				<tbody>
					<tr id="roomtype">
						<td>贤心</td>
						<td style="color: rgb(238 44 44);font-size: 15px; font-weight: 600;">￥1000</td>
						<td>张三</td>
						<td>12345678</td>
						<th>入住时间</th>
						<th>预计退房时间</th>
						<th>实际退房时间</th>
					</tr>
					<tr>
						<td>许闲心</td>
						<td style="color: rgb(238 44 44);font-size: 15px;font-weight: 600;">￥1000</td>
						<td>李四</td>
						<td>12345678</td>
						<th>入住时间</th>
						<th>预计退房时间</th>
						<th>实际退房时间</th>
					</tr>
				</tbody>
			</table>
		</div>
  
  <div class="layui-footer">
    <!-- 底部固定区域 -->
    © 版权归酒店所有
  </div>
</div>
<script src="layui.js"></script>
<script>
//JavaScript代码区域
layui.use('element', function(){
  var element = layui.element;
  
});
</script>
</body>
</html>